@extends('public.dashboard_base')
@section('title', '网站设置')
@section('content')
    <div class="control_panel_content">
        <div class="navBreadcrumb">
            <ul>
                <li>管理员菜单</li>
                <li><a href="/member/manager/setting">网站设置</a></li>
            </ul>
        </div>
        <div class="panel">
            <div class="sub_nav_container" style="margin-bottom: 10px">
                <ul class="clearfix">
                    <li class="active"><a href="">网站设置</a></li>
                </ul>
            </div>

            <script type="text/html" id="toolbar">
                <div class="layui-btn-container">
                    <button class="layui-btn layui-btn-sm layui-btn-primary" lay-event="site">网站设置<span class="event_site"></span></button>
                    <button class="layui-btn layui-btn-sm layui-btn-primary" lay-event="withdrawal">提现设置<span class="event_withdrawal"></span></button>
                    <button class="layui-btn layui-btn-sm layui-btn-primary" lay-event="email">邮件设置<span class="event_email"></span></button>
                    <button class="layui-btn layui-btn-sm layui-btn-primary" lay-event="alipay">支付宝<span class="event_alipay"></span></button>
                </div>
            </script>
            <table id="table" lay-filter="table"></table>

            <script type="text/html" id="nameTpl">
                @{{#  if(d.name == 'site_name'){ }}
                网站名称
                @{{#  } }}
                @{{#  if(d.name == 'site_logo'){ }}
                网站LOGO
                @{{#  } }}
                @{{#  if(d.name == 'keywords'){ }}
                网站关键字
                @{{#  } }}
                @{{#  if(d.name == 'description'){ }}
                网站简介
                @{{#  } }}
                @{{#  if(d.name == 'icp_number'){ }}
                ICP号码
                @{{#  } }}
                @{{#  if(d.name == 'company_name'){ }}
                公司名称
                @{{#  } }}
                @{{#  if(d.name == 'center_tel'){ }}
                客服电话
                @{{#  } }}
                @{{#  if(d.name == 'center_qq'){ }}
                客服QQ
                @{{#  } }}


                @{{#  if(d.name == 'service_charge'){ }}
                手续费
                @{{#  } }}
                @{{#  if(d.name == 'min_amount'){ }}
                最小金额
                @{{#  } }}
                @{{#  if(d.name == 'max_amount'){ }}
                最大金额
                @{{#  } }}
                @{{#  if(d.name == 'accuracy'){ }}
                精度
                @{{#  } }}


                @{{#  if(d.name == 'MAIL_MAILER'){ }}
                协议类型
                @{{#  } }}
                @{{#  if(d.name == 'MAIL_HOST'){ }}
                服务器地址
                @{{#  } }}
                @{{#  if(d.name == 'MAIL_PORT'){ }}
                服务器端口
                @{{#  } }}
                @{{#  if(d.name == 'MAIL_USERNAME'){ }}
                用户名
                @{{#  } }}
                @{{#  if(d.name == 'MAIL_PASSWORD'){ }}
                密码
                @{{#  } }}
                @{{#  if(d.name == 'MAIL_ENCRYPTION'){ }}
                加密方式
                @{{#  } }}
                @{{#  if(d.name == 'MAIL_FROM_ADDRESS'){ }}
                发件人邮箱
                @{{#  } }}
                @{{#  if(d.name == 'MAIL_FROM_NAME'){ }}
                发件人
                @{{#  } }}


                @{{#  if(d.name == 'ALIPAY_appId'){ }}
                appId
                @{{#  } }}
                @{{#  if(d.name == 'ALIPAY_merchantPrivateKey'){ }}
                私钥
                @{{#  } }}
                @{{#  if(d.name == 'ALIPAY_alipayPublicKey'){ }}
                公钥
                @{{#  } }}
            </script>
            <script type="text/html" id="valueTpl">
                @{{#  if(d.name == 'service_charge'){ }}
                @{{ d.value }}%
                @{{#  }else  if(d.name == 'min_amount'){ }}
                @{{ d.value }}元
                @{{#  }else  if(d.name == 'max_amount'){ }}
                @{{ d.value }}元
                @{{#  }else  if(d.name == 'accuracy'){ }}
                @{{ d.value }}元
                @{{#  }else  if(d.name == 'MAIL_PASSWORD'){ }}
                ******
                @{{#  }else  if(d.name == 'ALIPAY_merchantPrivateKey'){ }}
                ******
                @{{#  }else  if(d.name == 'ALIPAY_alipayPublicKey'){ }}
                ******
                @{{#  }else { }}
                @{{ d.value }}
                @{{#  } }}
            </script>

        </div>

    </div>
@endsection
@section('script')
    <script>
        var config_type = 'base';
        $(function () {
            var link = $("#manager_setting");
            link.parent().parent().parent().addClass("active");
            link.parent().addClass("active");
        });

        //表格
        layui.table.render({
            elem: '#table'
            , id: 'id_table'
            , toolbar: '#toolbar'
            , url: '/member/manager/setting' //数据接口
            , method: 'POST'
            , headers: {'X-CSRF-TOKEN': '{{csrf_token()}}'}
            , parseData: function (res) { //res 即为原始返回的数据
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": res.count, //解析数据长度
                    "data": res.data //解析数据列表
                };
            }
            , cols: [[ //表头
                // {type: 'checkbox', fixed: 'left'}
                {field: 'name', title: '名称', width: 150, templet: '#nameTpl'}
                , {field: 'value', title: '属性', edit: 'text', templet: '#valueTpl'}
            ]]
            , defaultToolbar: [] //'filter', 'exports', 'print'
            ,done:function () {
                if (config_type =='base') {
                    $('.event_site').addClass('layui-badge-dot');
                }

            }
        });

        //监听单元格编辑
        layui.table.on('edit(table)', function (obj) {
            $.ajax({
                url: '/member/manager/setting/edit',
                type: "post",
                data: {'_token': '{{csrf_token()}}', 'data': obj.data, 'type': config_type},
                success: function (data) {
                    if (data.msg === 'success') {
                        layer.msg('成功', {icon: 1, time: 500}, function () {
                        })
                    } else {
                        layer.msg(data.msg, {icon: 2});
                    }
                },
                error: function (xhr, Status, error) {
                    layer.msg(Status + ':' + xhr.responseJSON.data, {icon: 2});
                }
            });
        });

        //监听工具栏事件
        layui.table.on('toolbar(table)', function (obj) {
            switch (obj.event) {
                case 'site':
                    config_type = 'base';
                    layui.table.reload('id_table', {
                        where: {
                            type: 'base'
                        }
                    });
                    $('.event_site').addClass('layui-badge-dot');
                    break;
                case 'withdrawal':
                    config_type = 'withdrawal';
                    layui.table.reload('id_table', {
                        where: {
                            type: 'withdrawal'
                        }
                    });
                    $('.event_withdrawal').addClass('layui-badge-dot');
                    break;
                case 'email':
                    config_type = 'email';
                    layui.table.reload('id_table', {
                        where: {
                            type: 'email'
                        }
                    });
                    $('.event_email').addClass('layui-badge-dot');
                    break;
                case 'alipay':
                    config_type = 'alipay';
                    layui.table.reload('id_table', {
                        where: {
                            type: 'alipay'
                        }
                    });
                    $('.event_alipay').addClass('layui-badge-dot');
                    break;
            }
        });

    </script>
@endsection
